import {useAccount, useConnect, useDisconnect} from "wagmi";
import {useIntl, useModel} from "umi";

export default function WalletButton() {
    const {address, isConnected} = useAccount()
    const intl = useIntl();
    const {inj} = useModel('user')

    const {connect} = useConnect({
        connector: inj,
        onError: (error, variables, context) => {
            // console.log('my', error, variables, context)
            // if (error === 'ResourceUnavailableRpcError: Requested resource not available')
            //     message.error('请打开链接小钱包')
        }
    })
    const {disconnect} = useDisconnect()
    let newStr = address?.substring(0, 6) + '...' + address?.substring(address?.length - 6)
    if (isConnected)
        return <div className='btn' onClick={() => disconnect()}>{newStr}</div>
    return <div className='btn' onClick={() => connect()}>{intl.formatMessage({id: 'HEADER_ROUTER_WALLET'})}</div>
}
